<?php
/**
 *   Kaltura Browser - administrator/components/com_kaltura/controllers/instances.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2011 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.application.component.controller' );
class KalturaControllerinstances extends JController {
	function __construct() {
		if(JRequest::getCmd('view') == '') {
			JRequest::setVar('view', 'default');
		}
		$this->item_type = 'Default';
		parent::__construct();
		$this->registerTask('addinstances', 'editinstances');
	}
	function editinstances() {
		$view =& $this->getView('editinstances', 'html');
		JRequest::setVar('hidemainmenu', 1);
		
		$model = $this->getModel('instances');
		$user =& JFactory::getUser();
		$view->setModel($model, true);
		
		$view->display();
	}
	function save() {
		$model = $this->getModel('instances');
		if ($model->store()) {
			$msg = JText::_('com_kaltura_instances_SAVED');
		} else {
			$msg = JText::_('com_kaltura_instances_ERROR_SAVED');
		}
		$link 	= 'index.php?option=com_kaltura&view=instances';
		$this->setRedirect($link, $msg);
	}
	function delete() {
		$model = $this->getModel('instances');
		$cid = JRequest::getVar( 'cid', array(0));
		if (!is_array($cid) || count($cid) < 1) {
			$msg = '';
			JError::raiseWarning(500, JText::_( 'SELECT_DELETE' ) );
		} else {
			foreach ($cid as $id) {
		        if (!$model->delete($id)) {
			        JError::raiseError(500, JText::_('DELETE_FAILED').'<pre>'.print_r($cid, true).'</pre>');
		        }
	        }
            $msg = count($cid).' '.JText::_( 'SELECTED_DELETE' );
            $cache = &JFactory::getCache('com_kaltura');
            $cache->clean();
	    }
		$this->setRedirect( 'index.php?option=com_kaltura&view=instances', $msg );
	}
	
	function newclone() {
	    $view =& $this->getView('editinstances', 'html');
		JRequest::setVar('hidemainmenu', 1);
		
		$model = $this->getModel('instances');
		$user =& JFactory::getUser();
		$view->setModel($model, true);
		$view->setClone(true);
		
		$view->display();
	}
}
?>
